var data = ['iphone 5', 'i pad', '三星笔记本', '佳能相机', '惠普打印机', '谢谢参与', '50元充值卡', '1000元超市购物券'],
    timer = null,
    flagRun = false;

window.onload = function () {
    var play = document.getElementById('play'),
        stop = document.getElementById('stop');
    // 开始抽奖
    play.onclick = handleClickPlay;
    stop.onclick = handleClickStop;
    // 键盘事件
    document.onkeyup = handleKeyUp;
}

var handleClickPlay = function (event) {
    play();
}

var handleClickStop = function (event) {
    stop();
}

var handleKeyUp = function (event) {
    event = event || window.event;
    var keyCodeEnter = 13;//key enter
    if (event.keyCode == keyCodeEnter) {
        handleKeyEnter();
    }
}

var handleKeyEnter = function (e) {
    if (!flagRun) {
        play();
        flagRun = true;
    } else {
        stop();
        flagRun = false;
    }
}

var play = function () {
    var title = document.getElementById('title');
    var play = document.getElementById('play');
    clearInterval(timer);
    timer = setInterval(function () {
        var random = Math.floor(Math.random() * data.length);
        title.innerHTML = data[random];
    }, 50);
    play.style.background = '#999';
}

var stop = function () {
    clearInterval(timer);
    var play = document.getElementById('play');
    play.style.background = '#036';
}